package com.platform.common.utils.excel;

import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFRow;

public class ExportTests {
	public static class UserInfo{
		String name;
		int age;
		public UserInfo(String name, int age) {
			this.name = name;
			this.age = age;
		}
	}
	
	public static void main(String[] args) throws Exception {
    	new ExcelExport<UserInfo>(new AbsExcelExportConfig<UserInfo>() {
			public List<String> getExcelHead() {
				return Arrays.asList(new String[]{"序号", "用户名称", "年龄"});
			}
			public List<UserInfo> getData(int pageIndex) {
				List<UserInfo> list = new ArrayList<UserInfo>();
				if(pageIndex == 5){
					// 只查询5页，模拟数据查询完
					return list;
				}
				list.add(new UserInfo("zhangsan", 16));
				list.add(new UserInfo("lisi", 18));
				return list;
			}
			public RenderResult renderRow(HSSFRow row, Integer rowInd, Integer colInd, UserInfo entity) {
				ExcelExport.insertCell(row, colInd++, rowInd);
				ExcelExport.insertCell(row, colInd++, entity.name);
				ExcelExport.insertCell(row, colInd++, entity.age);
				return RenderResult.FINISH;
			}
		}).export(new FileOutputStream(new File("D:\\download.xls")));
    }
}
